<?php
/**
 * Patient Signal Search and View by Organization subview. Used in index action in PatientSignalController.
 *
 * @package   views
 * @subpackage patientSignal
 * @since     1.0
 * @filesource
 */

Yii::app()->clientScript->registerScript('search-by-organization', "
$('#advanced-search-button').click(function(){
	$('#advanced-search-options').toggle('slow');
	if($(this).hasClass('advanced-search-toggle-expanded')){
		$(this).removeClass('advanced-search-toggle-expanded')
	}else{
		$(this).addClass('advanced-search-toggle-expanded')
	}
	return false;
});
$('#signal-by-organization-search').click(function(){
	$.fn.yiiListView.update('signal-by-organization-list', {
		data: $('#signal-by-organization-form').serialize()
	});
	return false;
});
");

?>

<div class="form">
	
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'signal-by-organization-form',
	'action'=>Yii::app()->createUrl($this->route),
	'method'=>'get',
)); ?>

	<div class="row span-9">
		<?php echo $form->label($byOrganizationModel,'organizationId'); ?>
		<?php echo $form->dropDownList($byOrganizationModel,'organizationId',
				CHtml::listData(User::getCurrentUser()->viewableOrganizations, 'id', 'name'),
				array('empty'=>'Please select an organization','style'=>'width:300px;')); ?>
	</div>
	<div class="row span-12 last">
		<?php echo CHtml::link('Advanced Search','#',array('id'=>'advanced-search-button','class'=>'advanced-search-toggle')); ?>
	</div>
	<div class="clear"></div>
	<div id="advanced-search-options" style="display:none;">

	<div class="row span-12 last">
		<?php echo $form->label($byOrganizationModel,'subject'); ?>
		<?php echo $form->textField($byOrganizationModel,'subject',array('size'=>30,'maxlength'=>255)); ?>
	</div>
	
	<div class="clear"></div>
	
	<div class="row span-4">
		<?php echo $form->label($byOrganizationModel,'ageMin'); ?>
		<?php echo $form->textField($byOrganizationModel,'ageMin',array('style'=>'width: 40px;','maxlength'=>3)); ?>
		-
		<?php echo $form->textField($byOrganizationModel,'ageMax',array('style'=>'width: 40px;','maxlength'=>3)); ?>
	</div>

	<div class="row span-4">
		<?php echo $form->label($byOrganizationModel,'gender'); ?>
		<?php echo $form->dropDownList($byOrganizationModel,'gender',DataUtil::getGenders(),array('empty'=>'All')); ?>
	</div>

	<div class="row span-5">
		<?php echo $form->label($byOrganizationModel,'disorderId'); ?>
		<?php echo $form->dropDownList($byOrganizationModel,'disorderId',CHtml::listData(Disorder::model()->active()->findAll(), 'id', 'name'),array('empty'=>'All')); ?>
	</div>
	<div class="row span-7 last">
		<?php echo $form->labelEx($byOrganizationModel,'recordingDateMin'); ?>
		<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker',array(
		    'model'=>$byOrganizationModel,
		    'attribute'=>'recordingDateMin',
			'htmlOptions'=>array(
				'style'=>'width: 110px',
			),
		    ));  
		?> -
		<?php 
		$this->widget('zii.widgets.jui.CJuiDatePicker',array(
		    'model'=>$byOrganizationModel,
		    'attribute'=>'recordingDateMax',
			'htmlOptions'=>array(
				'style'=>'width: 110px',
			),
		    ));  
		?>
	</div>
	<div class="clear"></div>
	</div>
	<div class="row buttons">
		<?php echo CHtml::submitButton('Search',array('id'=>'signal-by-organization-search')); ?>
		<?php echo CHtml::submitButton('Search and Download Result',array('id'=>'signal-by-organization-download','name'=>'download')); ?>
		<?php echo CHtml::resetButton('Clear'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- search-form -->


<?php
$this->widget('zii.widgets.CListView', array(
	'id'=>'signal-by-organization-list',
	'dataProvider'=>$byOrganizationModel->search(),
	'itemView'=>'_view',
	'emptyText'=>'No results found. Please select an organization and search again.',
));
?>